import { isTest } from './config'
import identityCodeValid from './identityCodeValid'

let isMobile = mobileNums => {
	mobileNums = parseInt(mobileNums)
	let telRegex = /^(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[8-9])[0-9]{8}$/
	return telRegex.test(mobileNums)
}

let chooseHost = hostList => {
	return isTest ? hostList[0] : hostList[1]
}

let hideNum = (num, beginLength, endLength) => {
	let len = num.length - beginLength - endLength
	let star = new Array(len + 1).join('*')
	return (
		num.substring(0, beginLength) + star + num.substring(num.length - endLength)
	)
}

let formatToArray = object => {
	if (!object) return
	if (Array.isArray(object)) {
		return object
	} else {
		return [object]
	}
}

export default {
	isMobile,
	chooseHost,
	identityCodeValid,
	hideNum, //隐藏部分数字
	formatToArray
}
